home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr26 / netprog.zip / NETPROG.TAR / net / unixstrcli.c < prev    next >
C/C++ Source or Header  |  1989-12-17  |  888b  |  45 lines

  1. /*
  2.  * Example of client using UNIX domain stream protocol.
  3.  */
  4.  
  5. #include    "unix.h"
  6.  
  7. main(argc, argv)
  8. int    argc;
  9. char    *argv[];
  10. {
  11.     int            sockfd, servlen;
  12.     struct sockaddr_un    serv_addr;
  13.  
  14.     pname = argv[0];
  15.  
  16.     /*
  17.      * Fill in the structure "serv_addr" with the address of the
  18.      * server that we want to send to.
  19.      */
  20.  
  21.     bzero((char *) &serv_addr, sizeof(serv_addr));
  22.     serv_addr.sun_family = AF_UNIX;
  23.     strcpy(serv_addr.sun_path, UNIXSTR_PATH);
  24.     servlen = strlen(serv_addr.sun_path) + sizeof(serv_addr.sun_family);
  25.  
  26.     /*
  27.      * Open a socket (an UNIX domain stream socket).
  28.      */
  29.  
  30.     if ( (sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
  31.         err_sys("client: can't open stream socket");
  32.  
  33.     /*
  34.      * Connect to the server.
  35.      */
  36.  
  37.     if (connect(sockfd, (struct sockaddr *) &serv_addr, servlen) < 0)
  38.         err_sys("client: can't connect to server");
  39.  
  40.     str_cli(stdin, sockfd);        /* do it all */
  41.  
  42.     close(sockfd);
  43.     exit(0);
  44. }
  45.